package com.soulkun.smarthome.ui.main.home.adapter

import android.content.Context
import android.view.View
import androidx.databinding.ObservableArrayList
import androidx.databinding.ViewDataBinding
import com.soulkun.smarthome.R
import com.soulkun.smarthome.databinding.AppRecycleItemMainHomeDeviceHistoryDataItemListBinding
import com.soulkun.smarthome.databinding.AppRecycleItemMainHomeDeviceHistoryDataListBinding
import com.soulkun.smarthome.databinding.AppRecycleItemMainHomeDeviceRecentDataListBinding
import com.soulkun.smarthome.logic.dto.DeviceDataDTO
import com.soulkun.smarthome.logic.vo.DeviceDataHistoryItemVO
import com.soulkun.smarthome.logic.vo.DeviceDataHistoryVO
import soulkun.library.mvvm.adapter.BaseDataBindingRecyclerViewAdapter

class AppMainHomeDeviceHistoryDataItemListAdapter(
    context: Context,
    dataList: ObservableArrayList<DeviceDataHistoryItemVO>
) : BaseDataBindingRecyclerViewAdapter<DeviceDataHistoryItemVO>(context, dataList) {

    override fun getContentLayoutResId(): Int {
        return R.layout.app_recycle_item_main_home_device_history_data_item_list
    }

    override fun setContentViewHolderCreateListener(binding: ViewDataBinding) {
    }

    override fun setContentViewHolderBindListener(binding: ViewDataBinding, dataPosition: Int) {
        (binding as AppRecycleItemMainHomeDeviceHistoryDataItemListBinding).deviceDataHistoryItemVO =
            dataList[dataPosition]
        binding.tvMainHomeDeviceHistoryDataItemListTextValue.text =
            if (dataList[dataPosition].unit == "布尔值") {
                dataList[dataPosition].unitSymbol.split("/").run {
                    if (dataList[dataPosition].value == "0") {
                        this[0]
                    }else{
                        this[1]
                    }
                }
            }else{
                dataList[dataPosition].value + dataList[dataPosition].unitSymbol
            }
    }

}